pub mod order;
use order::{process_delivery_order, process_timeout_order};

use sea_orm::DatabaseConnection;
use tokio_cron_scheduler::{Job, JobScheduler, JobSchedulerError};

pub async fn initialize_scheduler(
    db: DatabaseConnection,
) -> Result<JobScheduler, JobSchedulerError> {
    let sched = JobScheduler::new().await;

    match sched {
        Ok(sched) => {
            sched.start().await;

            sched
                .add(Job::new_async("0 * * * * ?", |_uuid, _l| {}))
                .await?;
            // sched.add(Job::new("0 * * * * ?", process_timeout_order));

            Ok(sched)
        }
        Err(e) => Err(e),
    }
}
